package utils

// 获取登入图文校验
import (
	"github.com/mojocn/base64Captcha"
	"image/color"
)

type Captcha struct {
	Id   string
	BS64 string
	Code int
}

//函数外面引用不能用自动推导 ：=，所有函数里面可以用
var store = base64Captcha.DefaultMemStore

func GetCaptcha() (id string, base64 string, err error) {
	rgbaColor := color.RGBA{R: 0, G: 0, B: 0, A: 0}
	fonts := []string{"wqy-microhei.ttc"}
	//生成driver,第一个参数高度，第二个宽度,背景文字的干扰,画线条数,背景颜色的指针
	driver := base64Captcha.NewDriverMath(50, 140, 0, 0, &rgbaColor, fonts)
	//store := base64Captcha.DefaultMemStore
	//driver := base64Captcha.DefaultDriverDigit
	//var store = base64Captcha.DefaultMemStore

	//使用前面的driver和store生成验证码实例
	captcha := base64Captcha.NewCaptcha(driver, store)

	//生成验证码
	id, base64, err = captcha.Generate()
	return id, base64, err
}

func VerityCaptcha(id string, ret_captcha string) bool {
	return store.Verify(id, ret_captcha, true)
}
